function log(a) {
    console.log(a)
}
function err(a) {
    console.error(a)
}
function dir(a) {
    console.dir(a)
}
function deb(a) {
    debugMode && log(a)
}
function assert(a) {
    a || log("assertion failed")
}
function here() {
    log("!!!")
}
var readOnly, browserPane, titleBar, treeList, gridScroll, gridIn, gridToolbar, butDelete, butRename, butDirNew, butUpload, butGetZip, butMarker, filesInfo;
function resized() {
    var a = $(window),
    b = a.width(),
    a = a.height() - browserPane.position().top - 80,
    b = Math.floor((b - browserPane.outerWidth()) / 2),
    b = Math.max(0, b);
    browserPane.css("left", b);
    browserPane.find("#tree_list, #grid_list").height(a);
    gridScroll.height(a - gridToolbar.outerHeight());
    divUploads.find("#queue #in").css("max-height", a + "px")
}
var infoLine, divUploads, infoMsgTimeOut, showHidden, deviceUri = g.getParameterByName("jsonp"),
debugMode = parseInt(g.getParameterByName("debug"));
function bindTexts(a) {
    for (var b = 1; b < arguments.length; b += 2) a.find("#" + arguments[b]).text(arguments[b + 1])
}
function bindExpandable(a, b) {
    a.find("#exp").attr("expanded", b)
}
var leVolume, leDir, leFile, leMedia, popupMenu, divProgress, menu, cover, localizedStrings = [];
function localize() {
    $.ajax({
        dataType: "json",
        url: "loc.json?cmd=localize",
        async: !1,
        success: function(a) {
            localizedStrings = a;
            $("[_title]").each(function() {
                var b = $(this);
                b.attr("title", a[b.attr("_title")])
            });
            $("[_text]").each(function() {
                var b = $(this);
                b.text(a[b.attr("_text")])
            });
            $("[_value]").each(function() {
                var b = $(this);
                b.attr("value", a[b.attr("_value")])
            })
        },
        error: function(a, b) {
            showError("Localize failed: " + b)
        }
    })
}
var DRAG_TARGET = 0,
DRAG_LEAVE = 1,
DRAG_DROP = 2;
function leDrag(a, b) {
    var c = b.parent();
    switch (a) {
    case DRAG_TARGET:
        c.closest("#tree_list").length && !isDirExpanded(c) && (this.timer = window.setTimeout(function() {
            onDirClicked(c, DIR_LIST_TREE)
        },
        1E3));
        this.setCopying = function(a) {
            this.copying !== a && (this.copying = a, this.toast.text(localizedStrings[a ? 21 : 22]))
        };
        this.setCopying(!1);
        this.toast.show();
        c.focus();
        this.validDest = !0;
        for (var e = getLeFullPath(c), d = this.sel.length; 0 <= --d;) {
            var f = getLeFullPath($(this.sel[d]));
            if (g.isPathInPath(f, e)) {
                this.validDest = !1;
                this.markTargetValid(!1);
                break
            }
        }
        break;
    case DRAG_DROP:
        if (!this.validDest) {
            showError("Destination is not valid");
            break
        }
        askCopyMove(c, this.sel, this.copying)
    }
}
function deleteDrag(a, b) {
    switch (a) {
    case DRAG_TARGET:
        this.toast.text(localizedStrings[2]).show();
        break;
    case DRAG_DROP:
        askToDelete(this.sel)
    }
}
function renameDrag(a, b) {
    switch (a) {
    case DRAG_TARGET:
        this.toast.text(localizedStrings[3]).show();
        break;
    case DRAG_DROP:
        askRename(this.sel)
    }
}
function zipDrag(a, b) {
    switch (a) {
    case DRAG_TARGET:
        this.toast.text(localizedStrings[30]).show();
        break;
    case DRAG_DROP:
        opDownloadAsZip(this.sel)
    }
}
function dragTreeScroll(a, b, c) {
    if (a == DRAG_TARGET) {
        var e = "up" == b.attr("id");
        c = c || this;
        c.timer = window.setTimeout(function() {
            var d = treeList.scrollTop(),
            f = treeList.find(".le_in").outerHeight() || 30;
            treeList.animate({
                scrollTop: d + f * (e ? -1 : 1)
            },
            75);
            dragTreeScroll(a, b, c)
        },
        100)
    }
}
function onDragBegin(a) {
    if (!readOnly) {
        var b = function() {};
        setButtonEnabled(butDelete, b);
        1 == a.length && setButtonEnabled(butRename, b);
        setButtonEnabled(butDirNew, !1);
        setButtonEnabled(butUpload, !1)
    }
    return {
        sel: a,
        onTargeted: function(a) {
            this.unTarget();
            this.currTarget = a;
            this.onDrag = window[a.attr("onDrag")];
            a.addClass("drag-hover");
            if (this.onDrag) this.onDrag(DRAG_TARGET, a)
        },
        unTarget: function() {
            this.currTarget && (this.currTarget.removeClass("drag-hover"), this.onDrag(DRAG_LEAVE, this.currTarget), this.onDrag = this.currTarget = void 0, this.timer && (window.clearTimeout(this.timer), this.timer = void 0), this.toast.hide(), this.markTargetValid(void 0))
        },
        drop: function() {
            var a = this.currTarget;
            a && (this._onDrag = this.onDrag, this.unTarget(), this._onDrag(DRAG_DROP, a))
        },
        toast: $("#drag-toast")
    }
}
function elementHitTest(a, b, c, e) {
    for (var d = null,
    f = a; f != e; f = f.parentNode) {
        if ("hidden" == f.style.visibility) return ! 1;
        var h = f.getBoundingClientRect();
        if (! (b >= h.left && c >= h.top && b < h.right && c < h.bottom)) return ! 1;
        if (f === a) {
            d = $(a);
            if (d.attr("disabled")) return ! 1;
            if (d.hasClass("drag_scroll")) break
        }
    }
    return d
}
function onDragMove(a, b) {
    var c = a.clientX,
    e = a.clientY,
    d = browserPane.parent().get(0),
    f = b.currTarget ? b.currTarget.get(0) : null;
    if (!f || !elementHitTest(f, c, e, d)) {
        for (var f = $("[onDrag]"), h = f.length; 0 <= --h;) {
            var l = elementHitTest(f[h], c, e, d);
            if (l) {
                b.onTargeted(l);
                return
            }
        }
        b.unTarget()
    }
}
function onDragEnd(a) {
    a.drop();
    updateMarked()
}
function dragMouseDown(a) {
    if (0 === a.button && !readOnly) {
        var b = $(this).closest(".le");
        if (getLeParent(b)) {
            var c = b.parent(),
            e = c.find(".le[marked]");
            if (!e.length) e = b;
            else if (0 > e.index(b)) return;
            var d = null,
            f = $(document);
            f.on("mousemove",
            function(b) {
                if (!d) {
                    var f = b.clientX - a.clientX,
                    k = b.clientY - a.clientY;
                    if (5 > Math.sqrt(f * f + k * k)) return;
                    d = [];
                    e.each(function() {
                        var b = {
                            le: $(this)
                        },
                        e = b.le.clone();
                        b.leDrag = e;
                        e.find("[onDrag]").removeAttr("onDrag");
                        e.addClass("dragged");
                        c.append(e);
                        e.width(b.le.width());
                        b.le.css("visibility", "hidden");
                        var f = b.le.offset();
                        e.offset(f);
                        b.relOffsX = f.left - a.clientX;
                        b.relOffsY = f.top - a.clientY;
                        d.push(b)
                    });
                    d.data = onDragBegin(e);
                    d.data.markTargetValid = function(a) {
                        d.forEach(function(b) { ! 1 === a ? b.leDrag.addClass("drag-target-invalid") : b.leDrag.removeClass("drag-target-invalid")
                        })
                    }
                }
                d.forEach(function(a) {
                    a.leDrag.offset({
                        left: b.clientX + a.relOffsX,
                        top: b.clientY + a.relOffsY
                    })
                });
                d.data.toast.offset({
                    left: b.clientX + 0,
                    top: b.clientY + 30
                });
                onDragMove(b, d.data)
            });
            f.one("mouseup",
            function(a) {
                f.off("mousemove");
                d && (d.forEach(function(a) {
                    a.leDrag.remove();
                    a.le.css("visibility", "visible")
                }), onDragEnd(d.data))
            });
            return ! 1
        }
    }
}
function flashReadOnly() {
    var a = $("#read_only");
    if (!a.is(":animated")) for (var b = {
        opacity: 0.2
    },
    c = {
        opacity: 1
    },
    e = 0; 3 > e; e++) a.animate(b, 100).animate(c, 100)
}
function deDrag(a) {
    if (readOnly) flashReadOnly();
    else {
        a = a.originalEvent;
        a.stopPropagation();
        a.preventDefault();
        var b = a.dataTransfer;
        a = a.type;
        var c = $(this);
        if ("dragenter" == a) {
            $(".drag-hover").removeClass("drag-hover");
            c.addClass("drag-hover");
            try {
                b.effectAllowed = "copy"
            } catch(e) {}
        } else "dragover" == a ? b.dropEffect = "copy": "dragleave" != a && "dragend" != a && "drop" != a || c.removeClass("drag-hover");
        "drop" == a && (a = this == gridIn[0] ? currentDir: c.closest(".le"), startUploadOfFiles(a, b.files))
    }
}
function gridListDrag(a) {
    currentDir ? deDrag.call(this, a) : dragPrevent(a)
}
function dragPrevent(a) {
    a = a.originalEvent;
    var b = a.dataTransfer,
    c = a.type;
    if ("dragenter" == c) try {
        b.effectAllowed = "none"
    } catch(e) {} else "dragover" == c && (b.dropEffect = "none");
    a.preventDefault();
    a.stopPropagation()
}
function processRightClick(a) {
    if (!getMarkedLeInGrid().length) {
        var b = $(this).closest(".le"),
        c = getLeName(b),
        e = popupMenu.clone();
        e.find("#title").text(c);
        var d = e.find("#item"),
        f = d.parent();
        d.remove();
        for (var h = isDir(b), l = !getLeParent(b), k = isLeHidden(b), s = [{
            text: 7,
            icon: "res/op_new_folder.png",
            isEnabled: function() {
                return h && !readOnly
            },
            fn: opNewDir
        },
        {
            text: 2,
            icon: "res/op_delete.png",
            isEnabled: function() {
                return ! readOnly && !l
            },
            fn: opDelete
        },
        {
            text: 3,
            icon: "res/op_rename.png",
            isEnabled: function() {
                return ! readOnly && !l
            },
            fn: opRename
        },
        {
            text: 30,
            icon: "res/download_zip.png",
            fn: opDownloadAsZip
        },
        {
            text: 31,
            icon: "res/op_download.png",
            isEnabled: function() {
                return ! h
            },
            fn: opDownload
        },
        {
            text: 32,
            icon: "res/op_hide.png",
            isEnabled: function() {
                return h && !l && "." !== c.charAt(0) && !k
            },
            fn: function() {
                opHideUnhide(b, !0)
            }
        },
        {
            text: 33,
            icon: "res/op_unhide.png",
            isEnabled: function() {
                return h && !l && "." !== c.charAt(0) && k
            },
            fn: function() {
                opHideUnhide(b, !1)
            }
        }], q = 0, p = 0; p < s.length; p++) {
            var m = s[p];
            if (!m.isEnabled || m.isEnabled()) {
                var t = d.clone();
                t.find("#text").text(localizedStrings[m.text]);
                t.find("img").attr("src", m.icon);
                t.click(m.fn,
                function(a) {
                    unCover();
                    a.data(b)
                });
                f.append(t); ++q
            }
        }
        if (q) return $("body").append(e),
        f = $(window),
        s = e.width(),
        d = e.height(),
        e.css("left", Math.min(f.width() - s, Math.max(0, a.clientX - s / 2))),
        f = f.height(),
        a = a.clientY,
        a + d >= f && (a = f - d),
        e.css("top", a),
        e.show(),
        coverShow(function() {
            e.fadeOut("fast",
            function() {
                e.remove()
            })
        }),
        !1;
        deb("No menu items")
    }
}
function UploadTask() {
    function a(a, c) {
        var e = c ? Math.floor(a / c * 100) : 0;
        A !== e && (A = e, e += "%", s.css("width", e), q.text(e));
        if (a) {
            if (n.tick(a - w)) {
                var e = n.getBytesPerSec(),
                d = g.getReadableFileSizeString(e) + "/s";
                p.text(d);
                if (n.isStable()) {
                    if (e) {
                        for (var d = 0,
                        f = b.find(".file"), h = f.length; 0 <= --h;) {
                            var l = $(f[h]).data("file");
                            l && (d += l.size)
                        }
                        e = Math.floor((d + (c - a)) / e + 0.5);
                        d = "-";
                        3600 < e && (d += Math.floor(e / 3600), e %= 3600);
                        f = Math.floor(e / 60);
                        10 > f && (d += "0");
                        d = d + f + ":";
                        e %= 60;
                        10 > e && (d += "0");
                        d += e
                    } else d = "?";
                    t.text(d)
                }
            }
        } else p.text("");
        w = a
    }
    deb("Creating upload task");
    0 == divUploads.find("#progress-circle").length && divUploads.append(divProgress.clone());
    var b = divUploads.find("#queue"),
    c = divUploads.find("#progress"),
    e = b.find("#in"),
    d = !1;
    b.find("#title").off().click(function() {
        d = !0
    });
    var f = divUploads.find(".file");
    f.hide();
    var h = b.find("#cancel_all"),
    l = null,
    k = !1;
    h.off().one("click",
    function() {
        deb("Cancel all uploads");
        divUploads.find(".file #cancel").trigger("click")
    });
    var s = c.find("#pos"),
    q = c.find("#percent"),
    p = c.find("#stat"),
    m = divUploads.find("#counter"),
    t = b.find("#remain_time");
    t.text("");
    m.hide();
    var n = new SpeedCounter,
    A = -1,
    w = 0;
    a(0, 0);
    var x = 0,
    r = 0,
    u = 0;
    this.showCounter = function() {
        1 < x ? (m.text(r + "/" + x), m.show()) : m.hide()
    };
    var D = null,
    E = this,
    F = 0,
    y = null;
    this.startNext = function() {
        var c = b.find(".file:first");
        if (0 == c.length) l = null,
        h.off(),
        divUploads.fadeOut("fast"),
        uploadTask = null,
        deb("Upload task done"),
        u && showInfoMsg("Files uploaded: " + u);
        else {++r;
            this.showCounter();
            c.stop(!0, !0);
            divUploads.append(c);
            l = c;
            var e = c.data("file");
            deb("Starting upload: " + e.name);
            g.fileIsFolder(e,
            function(b) {
                if (b) {
                    a(0, 0);
                    b = c.data("path");
                    var d = c.data("de"),
                    f = function(a) {
                        deb("Upload success " + a.length);
                        l = null;
                        y = a.vol_free_space || y;
                        entriesEqual(d, currentDir) && (F || (F = setTimeout(function() {
                            F = 0;
                            if (entriesEqual(d, currentDir) && (deb("Refresh curr dir"), onDirClicked(d, DIR_LIST_GRID), y)) {
                                var a = getLeVolume(d);
                                a && bindVolumeSize(a, y);
                                y = null
                            }
                        },
                        1E3)));
                        c.remove(); ++u;
                        E.startNext()
                    };
                    if (2 <= debugMode) {
                        if (! (4 <= debugMode)) {
                            var h = 0,
                            k = 0,
                            k = window.setInterval(function() {
                                h += 1;
                                100 <= h ? (clearInterval(k), f({
                                    length: e.size,
                                    vol_free_space: 98765
                                })) : a(Math.floor(e.size * h / 100), e.size)
                            },
                            100);
                            D = {
                                abort: function() {
                                    clearInterval(k)
                                }
                            }
                        }
                    } else {
                        var n = "cmd=file&size=" + e.size,
                        n = appendFileSystemParam(d, n);
                        D = ajaxCall(b, n, f, null, "POST", !0, {
                            xhr: function() {
                                var b = $.ajaxSettings.xhr();
                                b.upload && b.upload.addEventListener("progress",
                                function(b) {
                                    a(b.loaded, b.total)
                                });
                                return b
                            },
                            data: e,
                            error: function(a, b) {
                                deb("Upload failure: " + b);
                                l = null;
                                c.remove();
                                "abort" != b && (showError("Upload error: " + b), E.startNext())
                            },
                            processData: !1
                        })
                    }
                } else showError("Folders can't be uploaded: " + e.name),
                c.remove(),
                l = null,
                E.startNext()
            })
        }
    };
    this.add = function(a, b) {
        var c = getLeFullPath(a) + "/" + b.name,
        d = f.clone();
        d.data("de", a).data("file", b).data("path", c);
        d.find("#name").text(b.name);
        d.find("#size").text(g.getReadableFileSizeString(b.size));
        d.find("#cancel").click(function() {
            d.remove(); --x;
            if (l && d.get(0) === l.get(0)) {
                deb("Cancel active upload"); --r;
                l = null;
                D && (D.abort(), D = null);
                var b;
                b = appendFileSystemParam(a, "cmd=delete");
                ajaxCall(c, b,
                function(a, b) {},
                null, "DELETE");
                E.startNext()
            } else deb("Cancel scheduled upload"),
            E.showCounter();
            1 >= x && m.hide()
        });
        e.append(d);
        d.show(); ++x
    };
    var C = 0,
    z = $("#bottom_bar");
    divUploads.hover(function(a) { (k = "mouseenter" == a.type) ? (z.css("z-index", 11), coverShow(function() {
            b.stop(!0, !1);
            b.hide();
            z.css("z-index", "");
            d = !1
        }), b.show(), e.scrollTop(e.prop("scrollHeight")), C && (clearTimeout(C), C = 0)) : d || unCover()
    });
    b.hide();
    divUploads.fadeIn("slow")
}
var uploadTask = null;
function startUploadOfFiles(a, b) {
    var c = !uploadTask;
    c && (uploadTask = new UploadTask);
    for (var e = 0; e < b.length; e++) uploadTask.add(a, b[e]);
    uploadTask.showCounter();
    c && uploadTask.startNext()
}
function bindDragAndDropEvents(a, b) {
    a.on("dragenter", b).on("dragover", b).on("dragleave", b).on("dragend", b).on("drop", b)
}
function cssBgndImg(a, b) {
    a.css("background-image", 'url("' + b + '")')
}
var canPlayVideoMp4 = !1,
canPlayAudioMp3 = !1;
function detectMediaFeatures() {
    var a = $("<video>")[0];
    a instanceof HTMLMediaElement && a.canPlayType && (canPlayVideoMp4 = !!a.canPlayType("video/mp4"));
    a = $("<audio>")[0];
    a instanceof HTMLMediaElement && a.canPlayType && (canPlayAudioMp3 = !!a.canPlayType("audio/mpeg"))
}
function onReady() {
    showHidden = g.getBooleanPref("showHidden", !1);
    var a = $(window);
    a.resize(resized);
    a.on("beforeunload", beforePageClose);
    infoLine = $("#info_line #in");
    infoLine.hide();
    divUploads = $("#uploads");
    3 == debugMode && divUploads.show();
    browserPane = $("#browser_pane");
    cover = $("#cover");
    cover.on("contextmenu",
    function() {
        unCover();
        return ! 1
    });
    cover.click(unCover);
    a = $("#body");
    a.on("contextmenu",
    function(a) {
        return ! 1
    });
    localize();
    treeList = browserPane.find("#tree_list");
    var b = browserPane.find("#grid_list");
    gridScroll = b.find("#grid_scroll");
    gridIn = b.find("#grid_in");
    bindDragAndDropEvents(gridIn, gridListDrag);
    gridToolbar = b.find("#toolbar");
    filesInfo = gridToolbar.find("#files_info");
    var c = $("#repository");
    debugMode && $(".debug").show();
    var e = g.getScrollBarWidth(),
    b = b.find("#grid_in"),
    d = parseInt(b.css("width"));
    b.css("width", d + e + "px");
    e = $("#bgnd-img"); (b = g.getPref("bgnd")) && cssBgndImg(e, b);
    buttonDef = c.find(".but");
    leVolume = c.find("#le_volume");
    leDir = c.find("#le_dir");
    leFile = c.find("#le_file");
    leMedia = c.find("#le_media");
    popupMenu = c.find("#popup");
    leDir.find(".le_in").mousedown(dragMouseDown);
    b = leVolume.add(leDir).find(".le_in");
    b.click(onDirInClicked);
    bindDragAndDropEvents(b, deDrag);
    leDir.hover(dirHover);
    b = leFile.add(leMedia);
    b.click(onEntryClicked).mousedown(dragMouseDown);
    bindDragAndDropEvents(b, dragPrevent);
    c.find(".le_in").on("contextmenu", processRightClick);
    $(".le #mark").click(onMarkClicked);
    a.keydown(onKeyDown);
    divProgress = c.find("#progress-circle");
    $(".but").each(function() {
        if (this !== buttonDef.get(0)) {
            var a = $(this),
            b = buttonDef.clone();
            $.each(this.attributes,
            function() {
                "img" !== this.name && this.value && b.attr(this.name, this.value)
            });
            var c = a.attr("img");
            c && ( - 1 == c.indexOf("/") && (c = "res/" + c + ".png"), cssBgndImg(b.find(".icon"), c)); (c = a.html()) && b.html(b.html() + c);
            a.replaceWith(b);
            b.dblclick(function(a) {
                a.stopPropagation();
                a.preventDefault()
            })
        }
    });
    butDelete = gridToolbar.find("#delete");
    butRename = gridToolbar.find("#rename");
    butDirNew = gridToolbar.find("#dirNew");
    butUpload = gridToolbar.find("#upload");
    butGetZip = gridToolbar.find("#get_zip");
    butMarker = gridToolbar.find("#marker");
    menu = $("#menu");
    menu.hover(function() {
        menuHover(1)
    },
    function() {
        menuHover()
    });
    browserPane.show();
    resized();
    titleBar = $("#title_bar");
    bindDragAndDropEvents(browserPane.add(e).add(titleBar).add(cover), dragPrevent);
    titleBar.show();
    updateMarked(); (new Image).src = "res/wifi_menu_bgnd.9.png"; (new Image).src = "res/popup_item.png";
    detectMediaFeatures();
    debugMode && showInfoMsg("Ready!");
    if (!debugMode || 2 >= debugMode) a = g.getSessionPref("currDir"),
    listRoot(a);
    4 === debugMode && debugStartMediaViewer();
    5 === debugMode && debugStartAudioPlayer();
    6 === debugMode && debugStartTextViewer()
}
function centerDialog(a) {
    a.css("margin-left", "-" + a.outerWidth() / 2 + "px");
    a.css("margin-top", "-" + a.outerHeight() / 2 + "px")
}
function showDialog(a, b) {
    b && coverShow(function() {
        b();
        a.fadeOut(100)
    });
    centerDialog(a);
    a.fadeIn(100);
    return a
}
function opReloadPage() {
    $(window).off("beforeunload");
    location.reload()
}
function beforePageClose(a) {
    if (uploadTask) return "Uploads are in progress. Close page anyway?";
    a = $("#text_view");
    if (a.is(":visible") && a.hasClass("dirty")) return "Text editor has unsaved changes."
}
function showInfoMsg(a, b) {
    infoMsgTimeOut && (window.clearInterval(infoMsgTimeOut), infoMsgTimeOut = 0);
    var c = infoLine.find("#msg");
    a = g.nl2br(a);
    c.html(a);
    infoLine.stop(!0);
    infoLine.fadeTo(0, 1);
    c = a.length;
    c = Math.max(4E3, Math.min(15E3, 40 * c));
    infoLine.find("#icon").attr("err", b ? 1 : 0);
    3 !== debugMode && (infoMsgTimeOut = window.setTimeout(function() {
        infoMsgTimeOut = 0;
        infoLine.fadeOut(500)
    },
    c))
}
function showError(a) {
    a ? showInfoMsg(a, !0) : log("undefined error")
}
function sortEntries(a, b) {
    var c = a.t - b.t;
    return 0 != c ? c: a.n.toLowerCase().localeCompare(b.n.toLowerCase())
}
function prepareFileUri(a) {
    deviceUri && (a = "http://" + deviceUri + a);
    return a
}
function bindTitle(a, b) {
    var c = a.find("#title");
    c.text(b);
    showEllipsizedTextAsTitle(c)
}
function showEllipsizedTextAsTitle(a) {
    a.one("mouseenter", a,
    function(a) {
        a = a.data;
        this.offsetWidth < this.scrollWidth && a.attr("title", a.text())
    })
}
function bindIconUri(a, b) {
    b = prepareFileUri(b);
    b = b.replace("'", "\\'");
    cssBgndImg(a.find("#icon"), b)
}
function bindIconId(a, b) {
    b && bindIconUri(a, "/" + b + "?cmd=res_id")
}
function bindAppIcon(a, b) {
    bindIconUri(a, "/files/icon?cmd=ext_icon&suffix=" + b)
}
function bindThumbnail(a, b) {
    var c = g.urlEncode(b) + "?cmd=thumbnail";
    bindIconUri(a, c)
}
function BackgroundTask(a) { (this.le = a) ? a.find(".le_in").first().append(divProgress) : gridIn.append(divProgress)
}
BackgroundTask.prototype = {
    le: null,
    finished: function() {
        currTask == this && (currTask = null, divProgress.remove())
    },
    cancel: function() {
        this.canceled = !0;
        this.finished()
    },
    onError: function(a) {
        this.finished();
        log("bgndtask err: " + a)
    }
};
var currTask;
function setCurrTask(a) {
    currTask != a && (currTask && currTask.cancel(), currTask = a)
}
var currentDir, currNoSep;
function getLeParent(a) {
    return a ? a.data("parent") : null
}
function setButtonEnabled(a, b, c) {
    var e = !a.attr("disabled"),
    d = !!b;
    if (d != e || c) a.off("click"),
    d ? (a.removeAttr("disabled"), a.click(function() {
        b()
    })) : a.attr("disabled", "1")
}
function setCurrentDir(a) {
    a && (a = getDirInTreeList(a));
    currentDir && currentDir.removeAttr("active");
    currNoSep && currNoSep.removeClass("no_separator"); (currentDir = a) && a.attr("active", !0);
    setButtonEnabled(gridToolbar.find("#dirUp"), getLeParent(currentDir) ? opUpDir: null);
    if (a) {
        var b = a.prev();
        b && b.hasClass("le") || (b = a.parent(), b.hasClass("le") || (b = null));
        b && (b = b.find(".le_in").first(), b.addClass("no_separator"));
        currNoSep = b
    } else setButtonEnabled(butDirNew, !1),
    setButtonEnabled(butUpload, !1),
    filesInfo.find("#num_marked").hide(),
    filesInfo.hide();
    g.setSessionPref("currDir", getLeFullPath(a))
}
function getAllLeInGrid() {
    return gridIn.find(".le")
}
function getMarkedLeInGrid() {
    return gridIn.find(".le[marked]")
}
function collapseDir(a, b) {
    var c = a.find(".le");
    b || (c = c.add(getAllLeInGrid()));
    c.remove();
    a.data("no_children") || bindExpandable(a, !1)
}
function collapseAllSiblings(a) {
    for (; a.siblings(".le").each(function(a, c) {
        collapseDir($(c), !0)
    }), a = a.parent(".le"), a.length;);
}
function getFileNameWithouPath(a) {
    return a.substring(a.lastIndexOf("/") + 1)
}
function getLeFullPath(a) {
    return a.data("fullPath")
}
function getLeName(a) {
    a = getLeFullPath(a);
    return getFileNameWithouPath(a)
}
function getLeUri(a, b) {
    var c = getLeFullPath(a),
    c = g.urlEncode(c) + "?cmd=" + b,
    c = appendFileSystemParam(a, c);
    return c = prepareFileUri(c)
}
function getLeVolume(a) {
    for (; a && "le_volume" != a.attr("id");) a = getLeParent(a);
    return a
}
function appendFileSystemParam(a, b) {
    var c = a.data("fs");
    c && (b += "&fs=" + c);
    return b
}
function getLeFileUri(a) {
    return getLeUri(a, "file")
}
function getLeImageUri(a) {
    return getLeUri(a, "image")
}
function getLeThumbnailUri(a) {
    return getLeUri(a, "thumbnail")
}
function isDir(a) {
    return a.data("dir")
}
function isLeHidden(a) {
    return a.attr("le_hidden")
}
function logLe(a) {
    a && log(getLeFullPath(a))
}
function isEntryChildOf(a, b, c) {
    a = getLeFullPath(a);
    b = getLeFullPath(b);
    if (g.isPathInPath(b, a) && (c || a != b)) return ! 0
}
function entriesEqual(a, b) {
    return a && b ? getLeFullPath(a) == getLeFullPath(b) : !1
}
var numMarked = 0;
function updateMarked() {
    numMarked = getAllLeInGrid().filter("[marked]").length;
    setButtonEnabled(butDirNew, canCreateDir() ? opNewDir: null);
    setButtonEnabled(butUpload, canCreateDir() ? opUpload: null);
    setButtonEnabled(butDelete, canDelete() ? opDelete: null);
    setButtonEnabled(butRename, canRename() ? opRename: null);
    var a;
    butMarker.off("click");
    0 == numMarked ? (a = "on", butMarker.click(markAll)) : (a = "off", butMarker.click(clearAllMarked));
    cssBgndImg(butMarker.find(".icon"), "res/btn_check_" + a + ".png");
    a = filesInfo.find("#num_marked");
    0 == numMarked ? a.hide() : (a.find("#text").text(numMarked), a.show())
}
function setLeMark(a, b) {
    a = a.add(a.data("treeLe")).add(a.data("gridLe"));
    b ? a.attr("marked", 1) : a.removeAttr("marked")
}
function toggleMarked(a) {
    setLeMark(a, !a.attr("marked"));
    updateMarked()
}
function markAll() {
    getAllLeInGrid().each(function() {
        setLeMark($(this), !0)
    });
    updateMarked()
}
function clearAllMarked() {
    getMarkedLeInGrid().length && (getAllLeInGrid().each(function() {
        setLeMark($(this), !1)
    }), updateMarked())
}
function onMarkClicked(a) {
    var b = $(this).closest(".le");
    toggleMarked(b);
    a.stopPropagation()
}
function getDirInTreeList(a) {
    var b = a.data("treeLe");
    b && (a = b);
    return a
}
function onDirClicked(a, b) {
    void 0 === b && (b = DIR_LIST_DEFAULT);
    a = getDirInTreeList(a);
    var c = getLeFullPath(a);
    listDir(c, a, b);
    b === DIR_LIST_DEFAULT && collapseAllSiblings(a);
    0 !== (b & DIR_LIST_GRID) && setCurrentDir(a)
}
function onDirInClicked(a) {
    var b = $(this).closest(".le");
    a.ctrlKey ? toggleMarked(b) : (clearAllMarked(), onDirClicked(b))
}
function isDirExpanded(a) {
    return "true" == a.find("#exp").attr("expanded")
}
function onExpandClicked(a) {
    a.stopPropagation();
    a = $(this).closest(".le");
    isDirExpanded(a) ? currentDir && isEntryChildOf(currentDir, a) ? (collapseDir(a, !0), onDirClicked(a, DIR_LIST_GRID)) : collapseDir(a, !0) : onDirClicked(a, entriesEqual(currentDir, a) ? DIR_LIST_BOTH: currentDir ? DIR_LIST_TREE: DIR_LIST_DEFAULT)
}
function downloadFile(a) {
    window.location.assign(a)
}
function isMediaViewableMime(a) {
    return "video/mp4" == a && canPlayVideoMp4 || "image" == g.getMimeTypeBase(a)
}
function onEntryClicked(a) {
    var b = $(this);
    if (a.ctrlKey) toggleMarked(b);
    else { (a = b.data("mime")) || "root" != b.data("fs") || g.getExtension(getLeFullPath(b)) || (a = "text/plain");
        if (a) if (isMediaViewableMime(a)) {
            var c = [];
            a = getAllLeInGrid();
            for (var e = -1,
            d = 0; d < a.length; d++) {
                var f = $(a[d]); ! isDir(f) && isMediaViewableMime(f.data("mime")) && ( - 1 === e && f[0] === this && (e = c.length), c.push(f))
            }
            if ( - 1 !== e) {
                showMediaViewer(c, e);
                return
            }
            err("Media not found!")
        } else if ("audio/mpeg" == a) {
            if (canPlayAudioMp3) {
                c = [];
                a = getAllLeInGrid();
                e = -1;
                for (d = 0; d < a.length; d++) f = $(a[d]),
                "audio/mpeg" == f.data("mime") && ( - 1 === e && f[0] === this && (e = c.length), c.push(f));
                if ( - 1 !== e) {
                    startAudioPlay(c, e);
                    return
                }
            }
        } else if ("text" == g.getMimeTypeBase(a)) {
            startTextViewer(b);
            return
        }
        b = getLeFileUri(b);
        downloadFile(b)
    }
}
function getDirSize(a) {
    if (!currTask || !entriesEqual(currTask.le, a)) {
        var b = getLeFullPath(a);
        assert(b);
        if (b) {
            var c = new BackgroundTask(a);
            ajaxCall(b, "cmd=dir_size",
            function(b, c) {
                c.finished();
                showDirSize(a, b.size)
            },
            c, null, !0)
        }
    }
}
function showDirSize(a, b) {
    a = a.add(a.data("treeLe")).add(a.data("gridLe")).find("#dir_size:first");
    a.text(g.getReadableFileSizeString(b))
}
var lastDirHoverT;
function dirHover(a) {
    var b = $(this).closest(".le"),
    c = getLeVolume(b);
    if (c && "/" != getLeFullPath(c)) {
        var c = "mouseenter" == a.type,
        e = b.data("hoverTimer");
        c ? (lastDirHoverT && (window.clearTimeout(lastDirHoverT), lastDirHoverT = 0), e || (e = window.setTimeout(function() {
            getDirSize(b)
        },
        2E3), b.data("hoverTimer", e), lastDirHoverT = e), a.stopPropagation()) : e && (window.clearTimeout(e), b.removeData("hoverTimer"), lastDirHoverT === e && (lastDirHoverT = 0))
    }
}
function updateButtonsByReadOnly() {
    var a = $("#read_only");
    readOnly ? a.show() : a.hide()
}
function bindVolumeSize(a, b, c) {
    c || (c = a.data("totalSpace"));
    b = localizedStrings[6] + " " + g.getReadableFileSizeString(b) + "/" + g.getReadableFileSizeString(c);
    bindTexts(a, "file_size", b)
}
var wasReadOnly, DIR_LIST_TREE = 1,
DIR_LIST_GRID = 2,
DIR_LIST_BOTH = 3,
DIR_LIST_DEFAULT = 7;
function onDirListed(a, b, c, e) {
    b.finished();
    var d = 0 !== (c & DIR_LIST_GRID);
    c = 0 !== (c & DIR_LIST_TREE);
    d && clearAllMarked();
    readOnly = a.read_only;
    wasReadOnly !== readOnly && (wasReadOnly = readOnly, updateButtonsByReadOnly());
    var f = a.files;
    if (!f) return ! 1;
    e || f.sort(sortEntries);
    e = b.listPath;
    "/" != e && (e += "/");
    var h = f.length,
    l = new Date,
    k = b.le;
    k ? c && bindExpandable(k, a.empty ? "": !0) : k = treeList;
    c && k.find(".le").remove();
    d && getAllLeInGrid().remove();
    for (var s = 0,
    q = 0,
    p = a = 0; p < h; p++) {
        var m = f[p],
        t = m.hidden;
        if (!showHidden && t)++a;
        else {
            var n = null,
            A = m.t,
            w = m.n,
            x = e + w;
            switch (A) {
            case 0:
                n = leVolume.clone(!0);
                x = m.space_total;
                n.data("totalSpace", x);
                bindVolumeSize(n, m.space_free, x);
                var x = m.mount,
                r = m.icon_id;
                r && bindIconId(n, r);
                w || (w = "/"); (r = m.label) && (w = w + " (" + r + ")");
                break;
            case 1:
                n = leDir.clone(!0);
                m.has_children || (bindExpandable(n, ""), n.data("no_children", !0));
                bindIconId(n, m.icon_id);
                break;
            case 2:
                if (!d) continue;
                if (r = m.mime) {
                    var u = g.getMimeTypeBase(r);
                    if ("image" == u || "video" == u) n = leMedia.clone(!0),
                    bindThumbnail(n, x)
                }
                n || (n = leFile.clone(!0), (u = g.getExtension(w)) && bindAppIcon(n, u));
                r && n.data("mime", r);
                bindTexts(n, "time", g.formatShortDateTime(l, m.time), "file_size", g.getReadableFileSizeString(m.size))
            }
            if (n) { (r = m.fs) && n.data("fs", r);
                if (m = m.sym_link) w += " \u2192 " + m,
                "/" === m.charAt(0) && (x = m);
                bindTitle(n, w);
                n.data("fullPath", x);
                t && n.attr("le_hidden", 1);
                b.le && n.data("parent", b.le);
                2 != A ? (n.data("dir", 1), c && (t = n.clone(!0), t.data("dir", 1), t.data("treeLe", n), n.data("gridLe", t), n.find("#exp").click(onExpandClicked), k.append(n), n = t), ++s) : ++q;
                d && gridIn.append(n)
            }
        }
    }
    d && (gridIn.scrollTop(0), filesInfo.find("#num_dirs").text(s), filesInfo.find("#num_files").text(q), d = filesInfo.find("#num_hidden"), a ? (d.text("(" + a + " " + localizedStrings[20] + ")"), d.show()) : d.hide(), filesInfo.show(), updateMarked());
    b.le && (l = treeList.find(".le"), l.length && (d = treeList.height(), f = c = treeList.scrollTop(), e = b.le.find(".le_in"), h = e.outerHeight(), b = l.index(b.le), l = b * h, f = Math.min(Math.max(f, (b + e.length + 1) * h - d), l), f != c && treeList.animate({
        scrollTop: f
    },
    200)));
    return ! 0
}
function canDelete() {
    return ! readOnly && (numMarked || getLeParent(currentDir))
}
function doDelete(a, b, c) {
    function e() {
        function a(d, f) {
            if (f.canceled) deb("Deleting canceled"),
            b && b(!1);
            else {
                var k = d.ok; ++f.i !== f.sel.length && k || f.finished();
                if (k) {
                    if (l = d.vol_free_space || l, f.cd && isEntryChildOf(f.cd, h, !0) && (f.cd = getLeParent(h), deb("deleted curr dir or parent, new cd is " + getLeFullPath(f.cd))), f.i < f.sel.length) {
                        e();
                        return
                    }
                } else showError(localizedStrings[15] + " " + q);
                unCover();
                if (l) {
                    var p = f.cd.closest("#le_volume");
                    p && bindVolumeSize(p, l)
                }
                currentDir != f.cd && setCurrentDir(f.cd);
                f.cd && !c && listDir(getLeFullPath(f.cd), f.cd);
                b && b(k)
            }
        }
        var h = $(d.sel[d.i]),
        q = getLeFullPath(h),
        p = getFileNameWithouPath(q);
        1 < d.sel.length ? (p = "<b>" + (d.i + 1) + "/" + d.sel.length + "</b> " + g.htmlEncode(p), d.divMsg.html(p)) : d.divMsg.text(p);
        f ? (log("Simulate delete " + q), setTimeout(function() {
            a({
                ok: !0,
                vol_free_space: 1234
            },
            d)
        },
        0 == d.i ? 500 : 200)) : (p = appendFileSystemParam(h, "cmd=delete"), ajaxCall(q, p, a, d, "DELETE", !0))
    }
    var d = new BackgroundTask(currentDir);
    d.sel = a;
    d.i = 0;
    d.cd = currentDir;
    var f = 2 <= debugMode;
    f && setCurrTask(d);
    var h = showCancelableDialog("res/op_delete.png", 29, "",
    function() {
        if (d.i < a.length) {
            deb("Canceled deleting");
            var b = currTask == d;
            d.cancel();
            b && !c && onDirClicked(d.cd)
        }
    });
    d.divMsg = h.find("#msg");
    var l = null;
    e()
}
function askToDelete(a, b, c) {
    var e = 1 === a.length ? getLeName(a) : a.length + " " + localizedStrings[23];
    dlgOkCancel("res/op_delete.png", 2, e,
    function() {
        doDelete(a, b, c)
    })
}
function opDelete(a) {
    a || (a = getMarkedLeInGrid());
    a.length || (a = currentDir);
    askToDelete(a)
}
function copyMoveSingleFile(a, b, c, e, d, f) {
    var h = $(c[e]),
    l = getLeFullPath(h),
    k = getLeFullPath(b) + "/" + getFileNameWithouPath(l),
    k = "cmd=rename&n=" + encodeURIComponent(k),
    k = appendFileSystemParam(h, k);
    ajaxCall(l, k,
    function(h, k) {
        var p = h.ok; ++e != c.length && p || a.finished();
        p ? e < c.length ? copyMoveSingleFile(a, b, c, e, d, f) : (currentDir != d && setCurrentDir(d), listDir(getLeFullPath(d), d)) : showError(localizedStrings[24] + " " + l)
    },
    a, "PUT", f)
}
function doCopyMove(a, b, c) {
    var e = new BackgroundTask(a),
    d = getDirInTreeList(a);
    getLeFullPath(currentDir).length < getLeFullPath(d).legth && (d = currentDir);
    copyMoveSingleFile(e, a, b, 0, d, c)
}
function askCopyMove(a, b, c) {
    var e = 1 === b.length ? getLeName(b) : b.length + " " + localizedStrings[23],
    e = e + (" &rarr; " + getLeName(a));
    dlgOkCancel("res/op_move.png", c ? 21 : 22, e,
    function() {
        doCopyMove(a, b, c)
    })
}
function canRename() {
    return ! readOnly && (1 == numMarked || 0 == numMarked && getLeParent(currentDir))
}
function askRename(a, b) {
    function c(c) {
        var h = e + "/" + c,
        l = "cmd=rename&n=" + encodeURIComponent(h),
        l = appendFileSystemParam(a, l);
        ajaxCall(e + "/" + d, l,
        function(e, l) {
            l.finished();
            if (e.ok) {
                bindTitle(a, c);
                a.data("fullPath", h);
                var q = a.data("treeLe");
                q ? (bindTitle(q, c), q.data("fullPath", h)) : b || opDirRefresh();
                b && b(c)
            } else showError(localizedStrings[14] + " " + d)
        },
        new BackgroundTask(a), "PUT")
    }
    var e = getLeFullPath(a),
    d = getFileNameWithouPath(e),
    e = g.getParentPath(e);
    showNameDialog("res/op_rename.png", 3, d + " &rarr; [?]",
    function(a) {
        c(a)
    },
    {
        path: e
    },
    d)
}
function opRename(a) {
    a || (a = getMarkedLeInGrid());
    a.length || (a = currentDir);
    1 == a.length && (askRename(a), clearAllMarked())
}
function opDirRefresh() {
    if (currentDir) {
        var a = getLeFullPath(currentDir);
        listDir(a, currentDir)
    } else listRoot()
}
function opUpDir() {
    var a = getLeParent(currentDir);
    a && onDirClicked(a)
}
function opShowHidden() {
    showHidden = !showHidden;
    g.setPref("showHidden", showHidden);
    showInfoMsg(localizedStrings[8] + ": " + (showHidden ? localizedStrings[9] : localizedStrings[10]));
    opDirRefresh()
}
function canCreateDir() {
    return ! readOnly && !numMarked && currentDir
}
function opNewDir(a) {
    function b(b) {
        var d;
        d = appendFileSystemParam(a, "cmd=new_dir");
        ajaxCall(c + "/" + b, d,
        function(b, d) {
            d.finished();
            b.ok ? onDirClicked(a) : showError(localizedStrings[12] + " " + c)
        },
        new BackgroundTask(a), "PUT")
    }
    a || (a = currentDir);
    if (a) {
        var c = getLeFullPath(a);
        showNameDialog("res/op_new_folder.png", 7, c + "/",
        function(a) {
            b(a)
        },
        {
            path: c
        })
    }
}
function opUpload() {
    currentDir && gridToolbar.find("#in_upload").click()
}
function opUploadPick(a) {
    startUploadOfFiles(currentDir, a.target.files);
    a.target.files = null
}
function opDownloadAsZip(a) {
    function b() {
        var b = getFileNameWithouPath(f);
        d += "/" + b + ".zip";
        b = d + "?cmd=zip";
        if (a.length && !e) for (var c = 0; c < a.length; c++) var k = $(a[c]),
        k = encodeURIComponent(getLeName(k)),
        b = b + ("&f=" + k);
        b = prepareFileUri(b);
        deb(b);
        downloadFile(b)
    }
    if (currentDir) {
        var c = !a;
        c && (a = getMarkedLeInGrid());
        var e = 1 === a.length && isDir(a),
        d = getLeFullPath(e ? a: currentDir),
        f = 1 === a.length ? getLeFullPath(a) : d;
        c ? dlgOkCancel("res/download_zip.png", 30, 1 >= a.length ? f: a.length + " " + localizedStrings[23], b) : b()
    }
}
function opDownload(a) {
    a = getLeFileUri(a) + "&mime=application%2Foctet-stream";
    downloadFile(a)
}
function canHide(a) {
    getLeFullPath(a)
}
function opHideUnhide(a, b) {
    var c = "cmd=hide_unhide";
    b && (c += "&hide");
    ajaxCall(getLeFullPath(a), c,
    function(c, d) {
        d.finished();
        c.ok ? (a = a.add(a.data("treeLe")).add(a.data("gridLe")), b ? a.attr("le_hidden", 1) : a.removeAttr("le_hidden")) : showError("Error")
    },
    new BackgroundTask(a), "PUT")
}
function getBookmarkUrl() {
    var a = "http://www.lonelycatgames.com/internal/xplore/wifi";
    deviceUri && (a = "http://loc/xp-wifi/wifi/lcg-web");
    var b = location.href.replace(/\/$/, ""),
    a = a + ("?device_name=" + deviceInfo.deviceName + "&ip=" + encodeURIComponent(b));
    deviceInfo.gcmId && (a += "&reg_id=" + deviceInfo.gcmId);
    return a
}
function opExit() {
    ajaxCall("/", "cmd=quit",
    function(a, b) {
        b.finished();
        var c = getBookmarkUrl();
        a.ok && (c += "#quit");
        location.replace(c)
    },
    new BackgroundTask, "PUT")
}
function opBookmark() {
    window.open(getBookmarkUrl() + "#bookmark")
}
function buildGcmWakeUrl(a) {
    return "http://www.lonelycatgames.com/Xplore/Gcm.jsp?wifi=on&reg_id=" + a + "&time_to_live=10"
}
var password = "",
passHash;
function byteArrayToHexeHexString(a) {
    for (var b = "",
    c = 0; c < a.length; c++) {
        var e = a[c].toString(16);
        2 > e.length && (e = "0" + e);
        b += e
    }
    return b
}
function setPassword(a, b) {
    if (password = a) {
        var c = function() {
            var c = md5(a),
            d = function(a) {
                return c[a >>> 2] >>> 8 * (a & 3) & 255
            },
            d = [d(0) ^ d(6), d(1) ^ d(7), d(2) ^ d(8), d(3) ^ d(9), d(4) ^ d(10), d(5) ^ d(11)];
            passHash = byteArrayToHexeHexString(d);
            b()
        };
        "function" === typeof md5 ? c() : $.getScript("md5.js", c)
    } else passHash = void 0
}
function askPassword() {
    deb("Asking pass");
    showNameDialog("res/lock.png", 13, null,
    function(a) {
        log("Password entered");
        setPassword(a, listRoot)
    },
    {
        type: "password"
    },
    password)
}
function askDonation(a) {
    deb("Asking donation");
    var b = prepareFileUri("/" + a.icon_id + "?cmd=res_id");
    showCancelableDialog(b, a.title, a.text, listRoot)
}
function ajaxCall(a, b, c, e, d, f, h) {
    var l = g.urlEncode(a) + "?" + b;
    e && setCurrTask(e);
    passHash && (l += "&pass=" + passHash);
    var l = prepareFileUri(l),
    k = {
        dataType: "json",
        success: function(a, b) {
            c(a, e)
        },
        error: function(k, l) {
            if (e) {
                switch (k.status) {
                case 401:
                    e.finished();
                    askPassword();
                    return;
                case 403:
                    if ("{" == k.responseText.charAt(0)) {
                        var m = $.parseJSON(k.responseText);
                        if ("Donation required" === m.err) {
                            e.finished();
                            askDonation(m);
                            return
                        }
                    }
                }
                if (!e.wakeAttempt && deviceInfo.gcmId) deb("Try to wake up device"),
                e.wakeAttempt = !0,
                m = buildGcmWakeUrl(deviceInfo.gcmId),
                $.ajax(m, {
                    dataType: "json",
                    success: function(k) {
                        if (k.OK) deb("Successfully sent awake signal"),
                        ajaxCall(a, b, c, e, d, f, h);
                        else e.onError(l)
                    },
                    error: function() {
                        e.onError(l)
                    },
                    timeout: 8E3
                });
                else e.onError(l)
            }
        }
    };
    if (h) for (var s in h) k[s] = h[s];
    f || (k.timeout = 1E3 * (debugMode ? 5 : 10));
    d && (k.type = d);
    return $.ajax(l, k)
}
function ListingTask(a, b) {
    var c = new BackgroundTask(b);
    c.listPath = a;
    c.onError = function(a) {
        this.finished();
        showError("Listing folder error: " + a)
    };
    return c
}
function listDir(a, b, c) {
    void 0 === c && (c = DIR_LIST_DEFAULT);
    var e = "cmd=list";
    0 === (c & DIR_LIST_GRID) && (e += "&filter=dirs");
    e = appendFileSystemParam(b, e);
    ajaxCall(a, e,
    function(a, b) {
        currTask == b ? onDirListed(a, b, c) : (log("task not active"), b.finished())
    },
    new ListingTask(a, b))
}
var deviceInfo = {};
function listRoot(a) {
    function b(c, e) {
        if (onDirListed(c, e, DIR_LIST_TREE, !e.le)) {
            var d = (e.le || treeList).find(".le"),
            f = null,
            h = !0;
            if (a) {
                for (var l = 0; l < d.length; ++l) {
                    var k = $(d[l]),
                    s = getLeFullPath(k);
                    if (g.isPathInPath(s, a)) {
                        f = k;
                        s != a && (h = !1);
                        break
                    }
                }
                f || (f = e.le)
            } ! f && d.length && (f = $(d[0]));
            f && (d = getLeFullPath(f), h ? (listDir(d, f), setCurrentDir(f)) : (h = appendFileSystemParam(f, "cmd=list&filter=dirs"), ajaxCall(d, h, b, new ListingTask(d, f))))
        }
    }
    ajaxCall("/files", "cmd=list_root&filter=dirs",
    function(a, e) {
        deviceInfo.gcmId = a.gcm_id;
        var d = a.device_name;
        deviceInfo.deviceName = d;
        deviceInfo.deviceUuid = a.device_uuid;
        titleBar.find("#device_name").text(d);
        b(a, e)
    },
    new ListingTask("/"))
}
var coverAnim = 100;
function unCover() {
    cover.fadeOut(coverAnim);
    cover.trigger("dismiss")
}
function coverShow(a) {
    if (a) cover.one("dismiss", a);
    cover.fadeIn(coverAnim)
}
function menuHover(a) {
    var b = menu.find("#submenu");
    a ? cover.is(":visible") || (menu.css("z-index", 11), b.show(coverAnim), coverShow(function() {
        menu.css("z-index", "");
        b.hide(coverAnim);
        menu.removeAttr("active")
    })) : b.is(":visible") && unCover()
}
function getTreeSibling(a, b) {
    if (a) {
        var c = treeList.find(".le_in").parent(),
        e = c.index(a[0]) + b;
        if (0 <= e && e < c.length) return $(c[e])
    }
    return null
}
var keyShortcuts = {
    46 : function() {
        canDelete() && opDelete()
    },
    27 : function() {
        numMarked && clearAllMarked()
    },
    8 : function() {
        opUpDir()
    },
    113 : function() {
        canRename() && opRename()
    },
    33 : function() {
        opUpDir()
    },
    37 : function() {
        if (currentDir && !currTask) if (isDirExpanded(currentDir)) collapseDir(currentDir, !0);
        else {
            var a = getLeParent(currentDir);
            a && (setCurrentDir(a), onDirClicked(a))
        }
    },
    39 : function() {
        if (currentDir && !currTask) if ("false" === currentDir.find("#exp").attr("expanded")) onDirClicked(currentDir);
        else {
            var a = getTreeSibling(currentDir, 1);
            a && onDirClicked(a, DIR_LIST_GRID)
        }
    },
    38 : function() {
        if (!currTask) {
            var a = getTreeSibling(currentDir, -1);
            a && onDirClicked(a, DIR_LIST_GRID)
        }
    },
    40 : function() {
        if (!currTask) {
            var a = getTreeSibling(currentDir, 1);
            a && onDirClicked(a, DIR_LIST_GRID)
        }
    },
    13 : function() {
        opDirRefresh()
    },
    70 : function() {
        canCreateDir() && opNewDir()
    },
    72 : opShowHidden,
    65 : function(a) {
        if (!a.ctrlKey) return ! 1;
        markAll()
    },
    85 : opDirRefresh
},
keyDebugShortcuts = {
    112 : function() {
        less.watchMode ? (less.unwatch(), log("less unwatch")) : (less.watch(), log("less watch"))
    },
    114 : function() {
        lop.xui = 1
    },
    115 : function() {
        var a = new Blob(['<a id="a"><b id="b">hey!</b></a>'], {
            type: "text/html"
        });
        a.name = "Blob.html";
        var b = new Blob(["Hello my dear"], {
            type: "text/plain"
        });
        b.name = "Blob.txt";
        for (var c = leDir.clone().data("fullPath", "/sdcard/1"), e = 4 <= debugMode ? 20 : 1; 0 <= --e;) startUploadOfFiles(c, [a, b])
    },
    117 : function() {
        opDownloadAsZip()
    },
    118 : function() {
        4 === debugMode ? debugStartMediaViewer() : 5 === debugMode && debugStartAudioPlayer()
    }
};
function processKeyShortcuts(a, b, c) {
    if ((b = b[a.keyCode]) && !1 !== (c ? b.call(c, a) : b(a))) return ! 0
}
function onKeyDown(a) {
    cover.is(":visible") ? 27 == a.keyCode && (unCover(), a.preventDefault()) : processKeyShortcuts(a, keyShortcuts) || debugMode && processKeyShortcuts(a, keyDebugShortcuts) ? a.preventDefault() : debugMode && a.ctrlKey && 17 != a.keyCode && log("Key: " + a.key + ", code: " + a.keyCode)
}
function checkFileExists(a, b) {
    ajaxCall(a, "cmd=exists",
    function(a, e) {
        e.finished();
        var d = a.exists;
        void 0 !== d && b(d)
    },
    new BackgroundTask)
}
function enableElement(a, b) {
    b ? a.removeAttr("disabled") : a.attr("disabled", !0)
}
function setElementReadOnly(a, b) {
    b ? a.attr("readonly", !0) : a.removeAttr("readonly")
}
function showNameDialog(a, b, c, e, d, f) {
    var h = $("#dlgEnterName");
    cssBgndImg(h.find("#icon"), a);
    h.find("#title #text").text(localizedStrings[b]);
    h.find("#msg").html(c);
    d = d || {};
    var l = d.path,
    k = h.find("#in #text");
    a = 0;
    k.val(f);
    k.attr("type", d.type || "text");
    k.off();
    f && (a = f.length, l && (d = g.getExtension(f)) && (a -= d.length + 1));
    var s = h.find("input[type=submit]");
    l ? (enableElement(s, !1), k.on("input",
    function(a) {
        a = l + "/" + k.val();
        checkFileExists(a,
        function(a) {
            enableElement(s, !a)
        })
    })) : enableElement(s, !0);
    d = h.find("form");
    d.off();
    d.submit(function(a) {
        a.preventDefault();
        unCover();
        a = k.val();
        e(a)
    });
    showDialog(h,
    function() {});
    k.focus();
    k.get(0).setSelectionRange(0, a)
}
function dlgOkCancel(a, b, c, e, d, f) {
    var h = $("#dlgOkCancel");
    if (d) {
        var l = h.clone(!0);
        h.parent().append(l);
        h = l
    }
    cssBgndImg(h.find("#icon"), a);
    h.find("#title #text").text(localizedStrings[b]);
    h.find("#msg").html(c);
    a = h.find("#ok");
    a.off("click").click(function() {
        unCover();
        e()
    });
    h.find("#cancel").off("click").click(function() {
        unCover();
        f && f()
    });
    showDialog(h,
    function() {
        d && h.remove()
    });
    a.focus();
    return h
}
function showCancelableDialog(a, b, c, e) {
    var d = $("#dlgCancelable");
    cssBgndImg(d.find("#icon"), a);
    "number" === typeof b && (b = localizedStrings[b]);
    d.find("#title #text").text(b);
    d.find("#msg").html(c);
    showDialog(d, e);
    return d
}
function changeMediaVolume(a) {
    a = Math.round(10 * this.volume + a);
    this.volume = Math.max(0, Math.min(1, 0.1 * a))
}
function toggleMediaPlay() {
    this.paused ? this.play() : this.pause()
}
function showMediaViewer(a, b) {
    function c(a) {
        setButtonEnabled(fa, 0 < b ? h: null, a);
        setButtonEnabled(ga, b < z - 1 ? l: null, a)
    }
    function e() {
        z && (d(), M = window.setTimeout(function() {
            M = 0;
            J || b < z - 1 ? (deb("Slideshow next"), b = (b + 1) % z, t(b)) : (deb("Slideshow end"), r())
        },
        1E3 * Q))
    }
    function d() {
        M && (window.clearTimeout(M), M = 0)
    }
    function f() {
        var c = b,
        d = 0 < c ? getLeFileUri(a[c - 1]) : "",
        e = getLeFileUri(a[c]),
        c = c < z - 1 ? getLeFileUri(a[c + 1]) : "",
        f;
        for (f in K) if (f != d && f != e && f != c) {
            deb("Remove img from cache: " + getFileNameWithouPath(f));
            var h = K[f];
            h.is(":visible") || h.removeAttr("src");
            delete K[f]
        }
    }
    function h() {
        d();
        0 < b && t(--b)
    }
    function l() {
        d();
        b < z - 1 && t(++b)
    }
    function k(a, b) {
        var c = a[0],
        d = b.width(),
        e = b.height();
        "IMG" == c.tagName ? d / c.width < e / c.height ? a.css("width", d).css("height", "") : a.css("width", "").css("height", e) : "VIDEO" == c.tagName && (c.width = d, c.height = e)
    }
    function s(a, b) {
        var c = G.find(".canvas"),
        d = $("<div>");
        d.addClass("canvas").append(a);
        d.hide();
        G.append(d);
        k(a, d);
        m();
        d.fadeIn(T,
        function() {
            c.remove()
        }); ! b && I && e()
    }
    function q(a) {
        a.css("image-orientation", "from-image");
        s(a)
    }
    function p(a) {
        var b = getLeFileUri(a),
        c = getLeThumbnailUri(a, "thumbnail");
        a = $("<video>");
        var e = a[0];
        a.attr("poster", c);
        e.src = b;
        e.controls = !0; (b = g.getPref("volume")) || (b = 50);
        e.volume = parseInt(b) / 100;
        e.onvolumechange = function() {
            var a = Math.round(100 * this.volume);
            g.setPref("volume", a);
            showInfoMsg(localizedStrings[38] + " " + a + "%")
        };
        e.onended = function() {
            I && U && l()
        };
        s(a);
        B = a;
        I && U && (d(), e.play())
    }
    function m() {
        if (B) {
            B.removeAttr("poster");
            var a = B[0];
            a.src = "";
            a.onvolumechange = null;
            B = a.onended = null
        }
    }
    function t(d, e) {
        function h() {
            b < z - 1 && t(b + 1, !0);
            b && t(b - 1, !0)
        }
        var k = a[d],
        l = getLeName(k);
        e ? deb("Preload " + l) : (deb("Load " + l), c(), f(), V && O.text(d + 1 + "/" + z), S.text(l));
        e || aa.text("");
        if ("video" == g.getMimeTypeBase(k.data("mime"))) e || (p(k), h());
        else {
            var n = getLeImageUri(k),
            m = K[n];
            m ? (deb("Found in cache: " + l), e || (m.is(":visible") && (m = m.clone()), q(m), h())) : (W++||G.append(P), e || (k = getLeThumbnailUri(k, "thumbnail"), m = $("<img>"), m.attr("src", k), s(m, !0)), m = $("<img>"), m.on("load",
            function() {
                function a() {
                    deb("loadSuccess: " + l);
                    K && (d >= b - 1 && d <= b + 1 ? (deb("Cache img " + l), K[n] = m) : deb("Not caching img " + l), e || d !== b || (q(m), h())); --W || P.remove()
                }
                m.off();
                ca ? window.setTimeout(function() {
                    a(n)
                },
                2E3) : a(n)
            }), m.on("error",
            function(a) {
                m.off();
                err("Can't load image"); --W || P.remove();
                e || d !== b || (a = $("<div>"), a.text("Load error"), a.addClass("error"), G.append(a), s(a))
            }), m.attr("src", n))
        }
    }
    function n() {
        v.addClass("fullscreen");
        var a = v[0],
        b = $(document);
        a.requestFullscreen ? (a.requestFullscreen(), L = document.exitFullscreen, b.off("fullscreenchange").on("fullscreenchange",
        function(a) {
            document.fullScreenElement || A()
        })) : a.msRequestFullscreen ? (a.msRequestFullscreen(), L = document.msExitFullscreen, b.off("msfullscreenchange").on("msfullscreenchange",
        function(a) {
            document.msFullScreenElement || A()
        })) : a.mozRequestFullScreen ? (a.mozRequestFullScreen(), L = document.mozCancelFullScreen, b.off("mozfullscreenchange").on("mozfullscreenchange",
        function(a) {
            document.mozFullScreenElement || A()
        })) : a.webkitRequestFullscreen && (a.webkitRequestFullscreen(), L = document.webkitExitFullscreen, b.off("webkitfullscreenchange").on("webkitfullscreenchange",
        function(a) {
            document.webkitFullscreenElement || A()
        }));
        y()
    }
    function A() {
        v.removeClass("fullscreen");
        L && L.call(document);
        y()
    }
    function w() {
        return v.hasClass("fullscreen")
    }
    function x() {
        w() ? A() : n()
    }
    function r() {
        d();
        I && (I = !1, cssBgndImg(X.find(".icon"), "res/slideshow_on.png"))
    }
    function u() {
        I ? r() : (I = !0, cssBgndImg(X.find(".icon"), "res/slideshow_off.png"), B && U ? B[0].play() : e());
        deb("Slideshow " + I)
    }
    function D() {
        w() ? A() : C()
    }
    function E(a) {
        var b = B[0],
        c = b.currentTime;
        b.currentTime = 0 < a ? c + 30 : c - 5
    }
    function F() {
        w() && A();
        var a = Q,
        b = J,
        c = dlgOkCancel("res/op_settings.png", 40, localizedStrings[39],
        function() {
            Q !== a && g.setPref("slideshowDelay", Q = a);
            J !== b && g.setPref("slideshowRepeat", J = b)
        },
        !0),
        d = c.find("#buttons"),
        e = $("<div>" + localizedStrings[41] + ': <input type="range" size="4" min="2" max="10"> <span id="sec" style="min-width: 20px; display: inline-block; text-align: right;"></span> ' + localizedStrings[42] + "</div>");
        d.before(e);
        var f = e.find("input");
        f.val(a);
        var h = e.find("#sec"),
        e = function() {
            var b = parseInt(f.val());
            b && (b = Math.max(2, Math.min(10, b)), h.text(a = b))
        };
        f.change(e).on("input", e);
        f.change();
        e = $('<div style="margin-top: 10px;"><label><input type="checkbox"> ' + localizedStrings[44] + "</label></div>");
        d.before(e);
        d = e.find("input");
        b && d.attr("checked", "true");
        d.click(function() {
            b = this.checked
        });
        centerDialog(c)
    }
    function y() {
        G.find("img,video").each(function() {
            var a = $(this);
            k(a, a.parent())
        })
    }
    function C() {
        A();
        P.remove();
        ba.off("keydown").keydown(onKeyDown);
        v.off("dblclick");
        N.fadeOut(coverAnim,
        function() {
            N.remove()
        });
        da.off("resize", y);
        v.find(".but").off();
        r();
        m();
        K = null;
        v.fadeOut("fast",
        function() {
            G.find("img").removeAttr("src");
            G.find("div").remove()
        });
        ea && opDirRefresh()
    }
    var z = a.length,
    v = browserPane.find("#media_viewer"),
    G = v.find("#canvas"),
    O = v.find("#counter"),
    aa = v.find("#media_info");
    aa.text("");
    var S = v.find("#name");
    S.text("");
    var P = divProgress.clone(),
    ba = $("body"),
    H = v.find("#controls"),
    fa = H.find("#prev"),
    ga = H.find("#next"),
    Y = H.find("#download"),
    Z = H.find("#rename"),
    R = H.find("#delete"),
    X = H.find("#slideshow"),
    Q = g.getIntPref("slideshowDelay") || 5,
    J = g.getPref("slideshowRepeat"),
    J = null === J ? !1 : "true" == J,
    U = !0,
    V = 1 < z,
    ea = !1;
    readOnly ? (R.hide(), Z.hide()) : (R.show(), R.off().click(function() {
        w() && A();
        var d = b;
        askToDelete(a[d],
        function(e) {
            e && (ea = !0, deb("media del: " + d), a.splice(d, 1), (z = a.length) ? ((V = 1 < z) || O.hide(), b === d && (b >= z && (b = z - 1), f(), t(b)), c()) : C())
        },
        !0)
    }), Z.show().off().click(function() {
        w() && A();
        askRename(a[b],
        function(a) {
            S.text(a)
        })
    }));
    Y.off().click(function() {
        opDownload(a[b])
    });
    V ? O.show() : O.hide();
    var K = {};
    c(!0);
    var I = !1,
    M = 0,
    ca = !1,
    T = 400;
    ca && (T *= 5);
    var B = null,
    W = 0,
    L = null;
    w() && A();
    setButtonEnabled(X, z ? u: null, !0);
    shortcuts = {
        27 : D,
        8 : D,
        37 : function() {
            B && !B[0].paused ? E( - 1) : h()
        },
        39 : function() {
            B && !B[0].paused ? E(1) : l()
        },
        38 : function() {
            B && changeMediaVolume.call(B[0], 1)
        },
        40 : function() {
            B && changeMediaVolume.call(B[0], -1)
        },
        13 : function(a) {
            x()
        },
        46 : function() {
            R.click()
        },
        113 : function() {
            Z.click()
        },
        32 : function() {
            B ? (r(), toggleMediaPlay.call(B[0])) : u()
        },
        114 : F
    };
    var da = $(window);
    da.resize(y);
    v.dblclick(x);
    H = v.find("#close");
    Y = v.find("#fullscreen");
    v.find("#options").off().click(F);
    var N = cover.clone();
    N.hide().css("z-index", v.css("z-index") - 1);
    cover.parent().append(N);
    H.click(C);
    Y.off().click(x);
    ba.off("keydown").keydown(function(a) {
        if (cover.is(":visible")) return onKeyDown(a);
        processKeyShortcuts(a, shortcuts, this) && a.preventDefault()
    });
    N.fadeIn(coverAnim);
    v.fadeIn("fast");
    t(b);
    B && B[0].play()
}
function debugStartMediaViewer(a) {
    var b = $("<div>");
    b.data("fullPath", "/storage/sdcard1/Pictures/Rotated/90.jpeg").data("mime", "image/jpeg");
    var c = $("<div>");
    c.data("fullPath", "/storage/sdcard1/Pictures/Rotated/0.jpeg").data("mime", "image/jpeg");
    c = [b, c];
    a && (a = $("<div>"), a.data("fullPath", "/sdcard/Video/Hugo.mp4").data("mime", "video/mp4"), c = [b, a]);
    showMediaViewer(c, 0)
}
function debugStartAudioPlayer() {
    var a = $("<div>");
    a.data("fullPath", "/sdcard/Tests/Audio/Test.mp3");
    var b = $("<div>");
    b.data("fullPath", "/sdcard/Tests/Audio/Cruel Summer.mp3");
    startAudioPlay([a, b], 0)
}
function startTextViewer(a) {
    function b(a) { (E = a) ? k.addClass("dirty") : k.removeClass("dirty")
    }
    function c() {
        u = !0;
        r && r.abort();
        n.remove();
        D.fadeOut(coverAnim,
        function() {
            D.remove()
        });
        l.off("keydown").keydown(onKeyDown);
        q.val("").off();
        k.find(".but").off();
        k.fadeOut("fast")
    }
    function e() {
        m.text(this.value.length)
    }
    function d() {
        t.show("slow");
        F.hide("slow");
        setButtonEnabled(y, null, !0);
        y.show("slow");
        showInfoMsg(localizedStrings[48]);
        setElementReadOnly(q, !1);
        q.on("input",
        function(a) {
            E || (b(!0), p.text("* " + A), setButtonEnabled(y, f));
            e.call(this)
        })
    }
    function f(a) {
        if (E && !r) {
            s.append(n);
            setElementReadOnly(q, !0);
            var d = {
                type: "POST",
                xhr: function() {
                    var a = $.ajaxSettings.xhr();
                    return r = a
                },
                contentType: "text/plain; charset=utf-8",
                dataType: "json",
                data: q.val(),
                processData: !1,
                success: function(d) {
                    d.ok ? (showInfoMsg(localizedStrings[49]), b(!1), p.text(A), setButtonEnabled(y, null), a && c()) : (d = d.err) && !u && showError("Save error: " + d)
                },
                error: function() {
                    u || showError("Save error")
                },
                complete: function() {
                    r = null;
                    n.remove();
                    setElementReadOnly(q, !1)
                },
                headers: {},
                timeout: 3E4
            };
            C && (d.headers["x-bom"] = 1);
            $.ajax(x, d)
        }
    }
    function h() {
        if (E) {
            var a = dlgOkCancel("res/op_text_edit.png", 50, "",
            function() {
                f(!0)
            },
            !0,
            function() {
                c()
            });
            a.find("#ok").text(localizedStrings[9]);
            a.find("#cancel").text(localizedStrings[10])
        } else c()
    }
    var l = $("body"),
    k = browserPane.find("#text_view"),
    s = k.find("#canvas"),
    q = k.find("#text");
    q.text("");
    var p = k.find("#name"),
    m = k.find("#media_info");
    m.text("");
    var t = k.find("#edit_info");
    t.hide();
    var n = divProgress.clone(),
    A = getLeName(a);
    p.text(A);
    var w = getLeFullPath(a);
    q.on("contextmenu",
    function(a) {
        a.stopPropagation()
    });
    var x = g.urlEncode(w) + "?" + appendFileSystemParam(a, "cmd=text_file"),
    x = prepareFileUri(x),
    r = null,
    u = !1,
    D = cover.clone();
    D.hide().css("z-index", k.css("z-index") - 1);
    cover.parent().append(D);
    var E = !1;
    b(!1);
    a = k.find("#close");
    var F = k.find("#start_edit"),
    y = k.find("#save");
    setElementReadOnly(q, !0);
    y.hide();
    readOnly ? F.hide() : (F.show(), F.click(d));
    var C = null;
    a.click(h);
    enableElement(q, !1);
    shortcuts = {
        27 : h,
        69 : function(a) {
            if (!a.ctrlKey) return ! 1;
            F.is(":visible") && F.click()
        },
        83 : function(a) {
            if (!a.ctrlKey) return ! 1;
            f()
        }
    };
    l.off("keydown").keydown(function(a) {
        if (cover.is(":visible")) return onKeyDown(a);
        processKeyShortcuts(a, shortcuts, this) && a.preventDefault()
    });
    D.fadeIn(coverAnim);
    k.fadeIn("fast");
    s.append(n);
    r = new XMLHttpRequest;
    r.open("GET", x, !0);
    r.onreadystatechange = function(a) {
        if (4 == this.readyState) {
            n.remove();
            a = r = null;
            if (200 == this.status) if (C = "1" === this.getResponseHeader("x-bom"), "application/json" === this.getResponseHeader("Content-Type")) a = $.parseJSON(this.response),
            (a = a.err) || (a = "Unknown error");
            else {
                q.val(this.response);
                enableElement(q, !0);
                q.focus();
                e.call(q[0]);
                return
            } else u || (a = "Can't load text");
            showError(a);
            c()
        }
    };
    r.send()
}
function debugStartTextViewer() {
    var a = $("<div>");
    a.data("fullPath", "/sdcard/Tests/Text/tel.txt");
    startTextViewer(a)
}
function showHelp() {
    window.open("http://www.lonelycatgames.com/wiki/?id=xplore:in_web")
}
onerror = function(a, b, c) {
    a = {
        msg: a,
        line: c,
        url: getFileNameWithouPath(b),
        userAgent: navigator.userAgent
    };
    ajaxCall("", "cmd=web_error",
    function(a) {
        log("Error report sent " + a.ok)
    },
    null, "POST", !1, {
        data: JSON.stringify(a),
        processData: !1,
        contentType: "application/json",
        error: function() {}
    });
    if (!debugMode) return ! 0
};
function testBut() {
    flashReadOnly()
}
function startAudioPlay(a, b) {
    function c(a) {
        G = [];
        for (var b = [], c = 0; c < y; c++) c !== a && b.push(c);
        for (void 0 !== a && G.push(a); b.length;) c = Math.floor(Math.random() * b.length),
        G.push(b[c]),
        b.splice(c, 1)
    }
    function e(a) {
        setButtonEnabled(x, 0 < b ? f: null, a);
        setButtonEnabled(r, b < y - 1 || z ? h: null, a)
    }
    function d() {
        var c = b;
        G && (c = G[c]);
        var d = a[c],
        c = "";
        if (1 < y) {
            var f = b + 1 + "/" + y;
            A.text(f);
            c += f + "  "
        }
        f = g.urlEncode(d) + "?cmd=file";
        F && (f += "&fs=" + F);
        f = prepareFileUri(f);
        d = getFileNameWithouPath(d);
        c += d;
        w.text(d).removeAttr("title");
        showEllipsizedTextAsTitle(w);
        u.attr("src", f);
        e();
        u[0].play();
        n.attr("title", c)
    }
    function f() {
        0 < b && d(--b)
    }
    function h() {
        b == y - 1 && z && (b = -1, v && c());
        if (b < y - 1) d(++b);
        else return ! 1
    }
    function l(a) {
        processKeyShortcuts(a, shortcuts, this) && a.preventDefault()
    }
    function k() {
        p.find(".but").off();
        w.off();
        u.off();
        u[0].pause();
        u.removeAttr("src");
        n.removeAttr("title")
    }
    function s() {
        m.off("keydown").keydown(onKeyDown);
        n.is(":visible") || k()
    }
    function q() {
        m.off("keydown").keydown(l);
        showDialog(p, s)
    }
    for (var p = $("#dlgAudioPlay"), m = $("body"), t = p.find("#bgnd"), n = $("#audio_but"), A = p.find("#counter"), w = p.find("#name"), x = p.find("#prev"), r = p.find("#next"), u = p.find("audio"), D = p.find("#repeat"), E = p.find("#shuffle"), F = getLeParent(a[0]).data("fs"), y = a.length, C = 0; C < y; C++) a[C] = getLeFullPath(a[C]);
    var z = g.getBooleanPref("audioRepeat", !0),
    v = g.getBooleanPref("audioShuffle", !1),
    G = null;
    v && (c(b), b = 0); (C = g.getPref("volume")) || (C = 50);
    u[0].volume = parseInt(C) / 100;
    u.on("volumechange",
    function() {
        var a = Math.round(100 * this.volume);
        g.setPref("volume", a);
        showInfoMsg(localizedStrings[38] + " " + a + "%")
    });
    u.on("ended",
    function() { ! 1 === h() && n.is(":visible") && n.hide("fast", k)
    });
    u.error(function(a) {
        showError("Error opening audio")
    });
    D.attr("checked", z).click(function() {
        D.attr("checked", z = !z);
        g.setPref("audioRepeat", z);
        e()
    });
    E.attr("checked", v).click(function() {
        E.attr("checked", v = !v);
        g.setPref("audioShuffle", v);
        v ? c() : G = null
    });
    e(!0);
    shortcuts = {
        27 : unCover,
        8 : unCover,
        37 : f,
        39 : h,
        38 : function() {
            changeMediaVolume.call(u[0], 1)
        },
        40 : function() {
            changeMediaVolume.call(u[0], -1)
        },
        32 : function() {
            toggleMediaPlay.call(u[0])
        },
        36 : function() {
            t.click()
        }
    };
    d();
    p.find("#close").click(unCover);
    t.click(function() {
        n.one("click",
        function() {
            q();
            n.hide("fast")
        });
        n.show("fast");
        unCover()
    });
    q()
};